package com.qf.controller;

import com.qf.common.http.Result;
import com.qf.entiy.dto.Goods;
import com.qf.entiy.po.LoginMerchant;
import com.qf.service.impl.GoodsService;
import com.qf.service.impl.GoodsSkuService;
import com.qf.service.impl.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsTypeService goodsTypeService;
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private GoodsSkuService goodsSkuService;

    @RequestMapping("list")
    public String toList(Model model, LoginMerchant loginMerchant) {
        model.addAttribute("goodsList", goodsService.getGoodsList(loginMerchant));
        return "goods/list";
    }

    @RequestMapping("add")
    public String toAdd(Model model,@RequestParam(value = "id",required = false) Long id) {
        model.addAttribute("goodsTypeList", goodsTypeService.list());
        if (id != null){
            model.addAttribute("goods",goodsService.getById(id));
            model.addAttribute("skuList",goodsSkuService.getSkuListByGoodsId(id));
        }
        return "goods/add";
    }


}
